package com.czg.designmode.builder;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 套餐类
 *
 * @author chenzhigang
 */
public class Meal {

    private List<Item> items = new ArrayList<>();

    /**
     * 添加套餐
     *
     * @param item 食物
     */
    public void addItem(Item item) {
        items.add(item);
    }

    /**
     * 获取套餐价格
     *
     * @return 套餐价格
     */
    public BigDecimal getCost() {
        if (null == items || items.size() == 0) {
            return BigDecimal.ZERO;
        }
        BigDecimal cost = BigDecimal.ZERO;
        for (Item item : items) {
            cost = cost.add(item.price());
        }
        return cost.setScale(2, BigDecimal.ROUND_HALF_UP);
    }

    public void showItems() {
        if (null != items && items.size() > 0) {
            for (Item item : items) {
                System.out.println("name:" + item.name() + ",packing:" + item.packing().pack() + ",price:" + item.price());
            }
        }
    }

}
